package com.caonima.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caonima.factory.DaoFactory;
import com.caonima.vo.Config;

public class EditConfig extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int cid = Integer.parseInt(request.getParameter("cid"));
		String copyright = request.getParameter("copyright");
		//String tech = request.getParameter("tech");
		String email = request.getParameter("email");
		String address = request.getParameter("address");
		String postcode = request.getParameter("postcode");
		String tel = request.getParameter("tel");
		Config config = new Config();
		config.setCid(1);
		config.setCopyright(copyright);
		//config.setTech(tech);
		config.setEmail(email);
		config.setAddress(address);
		config.setPostcode(postcode);
		config.setTel(tel);
		boolean flag = false;
		try {
			flag = DaoFactory.getIConfigDaoInstance().doUpdate(config);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(flag == true) {
			response.sendRedirect(request.getContextPath() + "/admin/showconfig");
		}
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
